package sg.edu.nus.iss.vmcs.maintenance;

/*
 * Copyright 2011 ISS.
 * The contents contained in this document may not be reproduced in any
 * form or by any means, without the written permission of ISS, other
 * than for the purpose for which it has been supplied.
 *
 */

import java.awt.*;

import sg.edu.nus.iss.vmcs.store.*;
import sg.edu.nus.iss.vmcs.util.VMCSException;

/**
 * This interface object is a part of the Maintenance Panel. It is used by the
 * Maintainer to display the total number of Coins of each denomination that are
 * currently held in Cash Store. The object contains buttons to represent (and
 * select) the {@link Coin} denominations used in the vending machine. This class
 * inherits from Java AWT Panel Class.
 *
 * @version 1.0  07/12/2011
 * @author Team 7S - SE19
 */

public class CoinDisplay extends Panel {

/**
 * Title of the panel
 */
	public final static String TITLE = "Quantity of Coins Available";

	private StoreController storeCtrl;
	private MaintenanceController mCtrl;
	private ButtonItemDisplay bi;
	private int len;
	private int curIdx;

/**
 * This constructor creates an instance of the CoinDisplay
 * @param mctrl Maintenance Controller
 * @see MaintenanceController
 * @see StoreController
 * @see StoreItem
 * @see ButtonItemDisplay
 * @see CoinDisplayListener
 */	
	public CoinDisplay(MaintenanceController mctrl) {
		mCtrl = mctrl;
		storeCtrl = mCtrl.getMainController().getStoreController();

		len = storeCtrl.getStoreSize(Store.CASH);
		StoreItem[] items = storeCtrl.getStoreItems(Store.CASH);

		bi = new ButtonItemDisplay(TITLE, items, len);

		bi.addListener(new CoinDisplayListener(mCtrl));

		bi.clear();

		this.add(bi);

	}

/**
 * This operation activates the Coin Display if the parameter is TRUE. Otherwise,
 * the Coin Display is deactivated
 * @param st boolean Status for coin display (TRUe / FALSE)
 */
	public void setActive(boolean st) {
		bi.setActive(st);
	}

/**
 * Display the quantity of selected coin, clear other display.
 * @param idx Index to get the ButtonItem object from the collection
 * @param qty Quantity to display for the selected coin
 * @throws VMCSException Index overflow
 */
	public void displayQty(int idx, int qty) throws VMCSException {
		curIdx = idx;
		bi.clear();
		bi.displayQty(idx, qty);
	}

/**
 * get the current displayed coin index. This is used for updating when store MachinerySimulatorPanel is changed.
 * Not required.
 * @return curIdx Current Index in the collection
 */
	public int getCurIdx() {
		return curIdx;
	}
}